﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Wicresoft.Common;
using JDEduTrain.Framework.Entity;
using JDEduTrain.Framework.Business;

public partial class Page_ClassDetail : BaseAuthenticationPage
{
    public Guid ClassID
    {
        get
        {
            if (Request["ClassID"] != null)
                return new Guid(Request["ClassID"]);
            return Guid.Empty;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.UseTabber = true;
        if (!IsPostBack)
        {
            BindClass();
        }
    }

    protected void BindClass()
    {
        TrainClass trainClass = new TrainClass(ClassID);
        if (trainClass.Load())
        {
            tbBeginTime.Text = trainClass.BeginTime.ToShortDateString();
            tbClassName.Text = trainClass.ClassName;
            tbComment.Text = HttpUtility.HtmlDecode(trainClass.Comment);
            tbEndTime.Text = trainClass.EndTime.ToShortDateString();
            tbCourseInfo.Text = trainClass.CourseInfo;
            tbScore.Text = trainClass.Score.ToString();
            tbPlace.Text = trainClass.Place;
            tbLectorInfo.Text = trainClass.LectorInfo;
            tbTrainDay.Text = trainClass.TrainDayCount.ToString();
            tbHostUnit.Text = trainClass.HostUnit;
            tbTrainLevel.Text = trainClass.TrainLevel;
            tbCurriculum.Text = trainClass.Curriculum;
            tbDeptDisplayName.Text = trainClass.ApplyOrgan;
            tbApplyEndTime.Text = trainClass.ApplyEndTime.ToShortDateString();
            if (trainClass.Status == "终审通过" && trainClass.TrainType != "区组织部")
            {
                trToolMenu.Visible = false;
            }

        }

        BindOrder();

    }
    protected void btnAddInfo_Click(object sender, EventArgs e)
    {
        ClassOrder order = new ClassOrder();
        order.ID = Guid.NewGuid();
        order.OrderInfo = tbOrderInfo.Text;
        order.OrderName = tbOrderName.Text;
        order.ClassID = ClassID;
        order.BeginTime = DateTime.Now;
        order.EndTime = DateTime.Now;
        order.Save();
        tbOrderInfo.Text = string.Empty;
        tbOrderName.Text = string.Empty;
        string script = "<script>refrshDetail();</script>";
        ClientScript.RegisterStartupScript(this.GetType(), "Close", script);
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindClass();
    }
    protected void rptOrderInfo_ItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        ImageButton ibtnEdit = e.Item.FindControl("ibtnEdit") as ImageButton;
        ImageButton ibtnDelete = e.Item.FindControl("ibtnDelete") as ImageButton;
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            if (e.CommandName == "Delete")
            {
                Guid id = new Guid(ibtnDelete.CommandArgument);
                ClassOrder order = new ClassOrder(id, ClassID);
                if (order.Load())
                {
                    order.Delete();
                    BindClass();
                }
            }
            else
                if (e.CommandName == "Edit")
                {
                    Guid orderID = new Guid(ibtnEdit.CommandArgument);
                    Random ran = new Random();
                    string script = string.Format("<script>editOrderInfo('{0}');</script>", orderID);
                    ClientScript.RegisterStartupScript(this.GetType(), "Close", script);
                }
        }
    }

    protected void BindOrder()
    {

        DataTable dtOrder = BLTrain.GetOrderByClassID(ClassID);
        rptOrderInfo.DataSource = dtOrder;
        rptOrderInfo.DataBind();

    }


}
